<template>
  <div class="dashboard-editor-container">
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" >
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              注册用户
            </div>
            本月：<count-to :start-val="0" :end-val="userCount.monthCount" :duration="2600" class="card-panel-num" />
            <br>
            累计：<count-to :start-val="0" :end-val="userCount.totalCount" :duration="2600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" >
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="car" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              销售车辆
            </div>
            本月：<count-to :start-val="0" :end-val="saleCount.monthCount" :duration="3000" class="card-panel-num" />
            <br>
            累计：<count-to :start-val="0" :end-val="saleCount.totalCount" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="example" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              设备统计
            </div>
            激活：<count-to :start-val="0" :end-val="equipCount.monthCount" :duration="3000" class="card-panel-num" />
            <br>
            入库：<count-to :start-val="0" :end-val="equipCount.totalCount" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" >
          <div class="card-panel-icon-wrapper icon-shopping" style="padding: 0">
            <img style="height: 80px;width: 80px" :src="path+vehicleCount.vehicleImage" height="198" width="198"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              销冠车型
            </div>
            车型：<span style="font-size: 20px">{{vehicleCount.vehicleModel}}</span>
            <br>
            销量：<count-to :start-val="0" :end-val="vehicleCount.totalCount" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <el-col :xs="24" :sm="24" :lg="16">
        <line-chart :chart-data="vehicleChartData" />
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart :chart-data="pieData"/>
        </div>
      </el-col>
    </el-row>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <el-col :xs="24" :sm="24" :lg="12">
          <bar-chart :chart-data="barData" />
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <line-chart :chart-data="userChartData" />
      </el-col>
    </el-row>


  </div>
</template>

<script>
import LineChart from './dashboard/LineChart'
import PieChart from './dashboard/PieChart'
import BarChart from './dashboard/BarChart'
import {dataCount} from "@/api/base/lkUser";
import CountTo from "vue-count-to";
import {vehicleSaleChart,vehicleSalePie,vehicleSaleBar} from "@/api/base/equipment";

export default {
  name: 'Index',
  components: {
    LineChart,
    PieChart,
    BarChart,
    CountTo
  },
  data() {
    return {
      userCount:{
        monthCount:0,
        totalCount:0
      },
      saleCount:{
        monthCount:0,
        totalCount:0
      },
      equipCount:{
        monthCount:0,
        totalCount:0
      },
      vehicleCount:{
        vehicleModel:"",
        totalCount:0,
        vehicleImage:""
      },
      path:process.env.VUE_APP_BASE_API,
      vehicleChartData: {
        timeData:[],
        expectedData: [],
        title: '',
        name:''
      },
      userChartData: {
        timeData:[],
        expectedData: [],
        title: '',
        name:''
      },
      pieData:{
        name:[],
        data:[]
      },
      barData:{
        timeData:[],
        expectedData: []
      }
    }
  },
  created() {
    this.getUserCount();
    this.vehicleSaleChart();
    this.vehicleSalePie();
    this.vehicleSaleBar();
  },
  methods: {
    getUserCount(){
      dataCount().then(res => {
        this.userCount=res.userCount;
        this.saleCount=res.saleCount;
        this.equipCount=res.equipCount;
        this.vehicleCount=res.vehicleCount;
      });
    },
    vehicleSaleChart(){
      vehicleSaleChart().then(res => {
        this.vehicleChartData=res.vehicle;
        this.vehicleChartData.title="近一年月份车辆销售统计"
        this.vehicleChartData.name="销量"
        this.userChartData=res.user;
        this.userChartData.title="近一年月份用户注册数统计"
        this.userChartData.name="用户注册数量"
      });
    },
    vehicleSalePie(){
      vehicleSalePie().then(res => {
        this.pieData=res.data
      });
    },
    vehicleSaleBar(){
      vehicleSaleBar().then(res => {
        this.barData=res.data
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>

